package net.ib.rpc.util;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * bytes 의 MD5 Hash 값으로 아이디를 만든다.
 * 
 * @comment happy2v
 * 
 */
public final class IdGenerator {
	private IdGenerator() {
	}

	public static int getId(byte[] bytes) throws SysException {

		byte[] idHash = null;

		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.reset();
			md.update(bytes);
			idHash = md.digest();
		} catch (NoSuchAlgorithmException e) {
			throw new SysException("MD5 NoSuchAlgorithmException : ", e);
		}

		ByteBuffer byteBuf = ByteBuffer.wrap(idHash);
		byteBuf.order(ByteOrder.BIG_ENDIAN);
		return byteBuf.getInt();
	}
}
